cmake_minimum_required(VERSION 3.0.0)
project(STL_Utils VERSION 0.1.0)

message(STATUS "=======================================")
message(STATUS "项目名称")
message(STATUS "---------------------------------------")
message(STATUS "PROJECT_NAME:${PROJECT_NAME}")
message(STATUS "PROJECT_VERSION:${PROJECT_VERSION}")
message(STATUS "PROJECT_VERSION_MAJOR:${PROJECT_VERSION_MAJOR}")
message(STATUS "PROJECT_VERSION_MINOR:${PROJECT_VERSION_MINOR}")
message(STATUS "PROJECT_VERSION_PATCH:${PROJECT_VERSION_PATCH}")
message(STATUS "---------------------------------------")

message(STATUS "=======================================")
message(STATUS "变量输出")
message(STATUS "---------------------------------------")

message(STATUS "CMAKE_ROOT:${CMAKE_ROOT}")
message(STATUS "CMAKE_PREFIX_PATH:${CMAKE_PREFIX_PATH}")
message(STATUS "CMAKE_PROGRAM_PATH:${CMAKE_PROGRAM_PATH}")
message(STATUS "CMAKE_LIBRARY_PATH:${CMAKE_LIBRARY_PATH}")
message(STATUS "CMAKE_INCLUDE_PATH:${CMAKE_INCLUDE_PATH}")
message(STATUS "CMAKE_IGNORE_PATH:${CMAKE_IGNORE_PATH}")
message(STATUS "CMAKE_FRAMEWORK_PATH:${CMAKE_FRAMEWORK_PATH}")
message(STATUS "CMAKE_APPBUNDLE_PATH:${CMAKE_APPBUNDLE_PATH}")
message(STATUS "CMAKE_SYSROOT:${CMAKE_SYSROOT}")
message(STATUS "CMAKE_SYSROOT_COMPILE:${CMAKE_SYSROOT_COMPILE}")
message(STATUS "CMAKE_SYSROOT_LINK:${CMAKE_SYSROOT_LINK}")
message(STATUS "CMAKE_SYSTEM_APPBUNDLE_PATH:${CMAKE_SYSTEM_APPBUNDLE_PATH}")
message(STATUS "CMAKE_SYSTEM_FRAMEWORK_PATH:${CMAKE_SYCMAKE_SYSTEM_FRAMEWORK_PATHSROOT}")
message(STATUS "CMAKE_SYSTEM_IGNORE_PATH:${CMAKE_SYSTEM_IGNORE_PATH}")
message(STATUS "CMAKE_SYSTEM_INCLUDE_PATH:${CMAKE_SYSTEM_INCLUDE_PATH}")
message(STATUS "CMAKE_SYSTEM_LIBRARY_PATH:${CMAKE_SYSTEM_LIBRARY_PATH}")
message(STATUS "CMAKE_SYSTEM_PREFIX_PATH:${CMAKE_SYSTEM_PREFIX_PATH}")
message(STATUS "CMAKE_SYSTEM_PROGRAM_PATH:${CMAKE_SYSTEM_PROGRAM_PATH}")
message(STATUS "CMAKE_BINARY_DIR:${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_CACHEFILE_DIR:${CMAKE_CACHEFILE_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR:${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "CMAKE_CURRENT_FUNCTION_LIST_DIR:${CMAKE_CURRENT_FUNCTION_LIST_DIR}")
message(STATUS "CMAKE_CURRENT_LIST_DIR:${CMAKE_CURRENT_LIST_DIR}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR:${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "CMAKE_SOURCE_DIR:${CMAKE_SOURCE_DIR}")
message(STATUS "PROJECT_BINARY_DIR:${PROJECT_BINARY_DIR}")
message(STATUS "PROJECT_SOURCE_DIR:${PROJECT_SOURCE_DIR}")

message(STATUS "---------------------------------------")

#############################################
# 1 设置编译版本
#############################################

set(CMAKE_BUILD_TYPE "Debug")
# set(CMAKE_BUILD_TYPE "Release")

if(${CMAKE_BUILD_TYPE} MATCHES "Release")
    message(STATUS "Release版本")
    set(BuildType "Release")
else()
    set(BuildType "Debug")
endif()

message(STATUS "=======================================")

message(STATUS "---------------------------------------")
message(STATUS "${BuildType}版本")
message(STATUS "---------------------------------------")







#############################################
# 3 编译选项
#############################################

# 使能c++11
set(CMAKE_CXX_STANDARD 11)
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if(${CMAKE_BUILD_TYPE} MATCHES "Release")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=unused-variable") # 好像是设置吧未使用警告当成错误处理
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=0")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0")
else()
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
#     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=0")
#     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0")
endif()

# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") #TODO 未知


message(STATUS "=======================================")
message(STATUS "编译选项")
message(STATUS "---------------------------------------")
message(STATUS "CMAKE_C_FLAGS:${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS}")
message(STATUS "---------------------------------------")

#############################################
# 3 编译选项
#############################################

# 增加预定义
add_definitions(
    -DTIXML_USE_STL
    # 产品包测试注释掉
    # -DLYL_DEBUG
    # -DSKIP_XUEAN
    -DSTL_JSON_ENABLE
    -DPOSIX
    -DDEBUG_
)

# add_definitions("-Werror") # 把警告当作错误。出现任何警告就放弃编译。
# add_definitions("-Wall") # 会打开一些很有用的警告选项,建议编译时加此选项。
add_definitions("-w") # 不输出警告,建议开发初期使用,后期还有消灭警告为好。
add_definitions("-g") #包含调试信息
add_definitions("-ffunction-sections") # 未知
add_definitions("-fdata-sections") # 未知

message(STATUS "=======================================")
message(STATUS "库搜索路径")
message(STATUS "---------------------------------------")
get_property(temp_directories DIRECTORY PROPERTY COMPILE_DEFINITIONS)
message(STATUS "COMPILE_DEFINITIONS: ${temp_directories}")
get_property(temp_directories DIRECTORY PROPERTY COMPILE_OPTIONS)
message(STATUS "COMPILE_OPTIONS: ${temp_directories}")
message(STATUS "---------------------------------------")

#############################################
# 4 头文件搜索路径
#############################################

include_directories(
    "src/STL_Utils/"
    "src/STL_Async/"
    "src/STL_Base64/"
    "src/STL_CRC32/"
    "src/STL_Crypt/"
    "src/STL_CURL/"
    "src/STL_Digest/"
    "src/STL_FileSystem/"
    "src/STL_HttpServer/"
    "src/STL_Json/"
    "src/STL_Linux/"
    "src/STL_Log/"
    "src/STL_MD5/"
    "src/STL_Mqtt/"
    "src/STL_Mysql/"
    "src/STL_MysqlConnPool/"
    "src/STL_Path/"
    "src/STL_REGEX/"
    "src/STL_RtspEnableTest/"
    "src/STL_SafeQueue/"
    "src/STL_Scheduler/"
    "src/STL_Serial/"
    "src/STL_TcpClientMgr/"
    "src/STL_TcpServer/"
    "src/STL_Text/"
    "src/STL_Thread/"
    "src/STL_Timestamp/"
    "src/STL_URL/"
    "src/STL_Utils/"
    "src/STL_XML/"
    "src/STL_YAML/"
    }

message(STATUS "=======================================")
message(STATUS "头文件搜索路径")
message(STATUS "---------------------------------------")
get_property(temp_directories DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message(STATUS "INCLUDE_DIRECTORIES: ${temp_directories}")
message(STATUS "---------------------------------------")




#############################################
# 5 库文件搜索路径
#############################################

link_directories("/home/liuyuelong/workspace/libs/jrtplib/lib") # TODO 修改
link_directories("./lib/x64/")
link_directories("./lib/x64/freesdp")

message(STATUS "=======================================")
message(STATUS "库搜索路径")
message(STATUS "---------------------------------------")
get_property(temp_directories DIRECTORY PROPERTY LINK_DIRECTORIES)
message(STATUS "LINK_DIRECTORIES: ${temp_directories}")
message(STATUS "---------------------------------------")

#############################################
# 6 源码路径
#############################################

aux_source_directory(./src/STL_Utils SRC_TEMP_LIST)
aux_source_directory(./src/STL_Async SRC_TEMP_LIST)
aux_source_directory(./src/STL_Base64 SRC_TEMP_LIST)
aux_source_directory(./src/STL_CRC32 SRC_TEMP_LIST)
aux_source_directory(./src/STL_Crypt SRC_TEMP_LIST)
aux_source_directory(./src/STL_CURL SRC_TEMP_LIST)
aux_source_directory(./src/STL_Digest SRC_TEMP_LIST)
aux_source_directory(./src/STL_FileSystem SRC_TEMP_LIST)
aux_source_directory(./src/STL_HttpServer SRC_TEMP_LIST)
aux_source_directory(./src/STL_Json SRC_TEMP_LIST)
aux_source_directory(./src/STL_Linux SRC_TEMP_LIST)
aux_source_directory(./src/STL_Log SRC_TEMP_LIST)
aux_source_directory(./src/STL_MD5 SRC_TEMP_LIST)
aux_source_directory(./src/STL_Mqtt SRC_TEMP_LIST)
aux_source_directory(./src/STL_Mysql SRC_TEMP_LIST)
aux_source_directory(./src/STL_MysqlConnPool SRC_TEMP_LIST)
aux_source_directory(./src/STL_Path SRC_TEMP_LIST)
aux_source_directory(./src/STL_REGEX SRC_TEMP_LIST)
aux_source_directory(./src/STL_RtspEnableTest SRC_TEMP_LIST)
aux_source_directory(./src/STL_SafeQueue SRC_TEMP_LIST)
aux_source_directory(./src/STL_Scheduler SRC_TEMP_LIST)
aux_source_directory(./src/STL_Serial SRC_TEMP_LIST)
aux_source_directory(./src/STL_TcpClientMgr SRC_TEMP_LIST)
aux_source_directory(./src/STL_TcpServer SRC_TEMP_LIST)
aux_source_directory(./src/STL_Text SRC_TEMP_LIST)
aux_source_directory(./src/STL_Thread SRC_TEMP_LIST)
aux_source_directory(./src/STL_Timestamp SRC_TEMP_LIST)
aux_source_directory(./src/STL_URL SRC_TEMP_LIST)
aux_source_directory(./src/STL_Utils SRC_TEMP_LIST)
aux_source_directory(./src/STL_XML SRC_TEMP_LIST)
aux_source_directory(./src/STL_YAML SRC_TEMP_LIST)


SET(SRC_LIST
        ${SRC_TEMP_LIST}
        "./src/main.cpp"
        )

message(STATUS "=======================================")
message(STATUS "项目源文件列表")
message(STATUS "---------------------------------------")
foreach(src_filename ${SRC_LIST})
    message(STATUS ${src_filename})
endforeach(src_filename)
message(STATUS "---------------------------------------")

#############################################
# 7 目标生成
#############################################

add_executable(STL_Utils ${SRC_LIST})


#############################################
# 8 连接动态库静态库
#############################################

target_link_libraries(
    ${PROJECT_NAME} 
    -Wl,--start-group
)

target_link_libraries(
    ${PROJECT_NAME} 
    -lavformat
    -lavcodec
    -lavutil
)

set(
    LINK_LIB_LIST 
    yaml
    zlog
    pthread
    eXosip2 
    osip2 
    osipparser2
    mxml
    iconv 
    jthread 
    jrtp 
    pthread
    freesdpc
    freesdpf
    freesdpp
    freesdp
    hiredis
    mysqlclient
    mosquitto 
    json-c
    curl
)

target_link_libraries(
    ${PROJECT_NAME}
    ${LINK_LIB_LIST}
)

target_link_libraries(
    ${PROJECT_NAME}
    ${CMAKE_SOURCE_DIR}/lib/x64/srs_librtmp.a
    ${CMAKE_SOURCE_DIR}/lib/x64/libssl_temp.a
    ${CMAKE_SOURCE_DIR}/lib/x64/libcrypto_temp.a
    -lm
    -ldl
)

target_link_libraries(
    ${PROJECT_NAME} 
    -lssl
    -lcrypto
)

target_link_libraries(
    ${PROJECT_NAME} 
    -Wl,--end-group
)

message(STATUS "=======================================")
message(STATUS "连接库列表")
message(STATUS "---------------------------------------")
get_property(temp_target TARGET ${PROJECT_NAME} PROPERTY LINK_LIBRARIES)
message(STATUS "LINK_LIBRARIES: ${temp_target}")
message(STATUS "---------------------------------------")

#############################################
# 9 安装配置
#############################################

# 设置输出二进制文件的存放位置 ${PROJECT_SOURCE_DIR}/bin
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

#############################################
# 结束
#############################################
